<template>
  <view>
    <robin-editor
      class="editor"
      @cancel="hideEditor"
      @save="saveEditor"
      v-model="html"
      :tools="[
        'bold',
        'italic',
        'underline',
        'strike',
        'align-left',
        'align-center',
        'align-right',
        'font',
        'image',
        'clear',
        'undo',
        'redo',
        'preview',
      ]"
      :imageUploader="uploadImg"
      :muiltImage="false"
    />
  </view>
</template>

<script>
import { mapActions } from "vuex";
import {
  h5_urlToBase64,
  wx_imageToBase64,
  App_imgToBase,
} from "@/utils/urlTobase.js";
export default {
  data() {
    return {
      html: "",
      loadingFlag: false,
    };
  },

  methods: {
    ...mapActions("editor", ["editorStr_action"]),
    hideEditor() {
      uni.showModal({
        title: "提示",
        content: "确认退出？",
        success: (res) => {
          if (res.confirm) {
            uni.navigateBack({ delta: 1 });
          }
        },
      });
    },
    saveEditor(obj) {
      this.editorStr_action(obj.html);
      uni.navigateBack({ delta: 1 });
    },
    async uploadImg(url, callback) {
      return;
      let baseStr = null;
      /* #ifdef H5 */
      baseStr = await h5_urlToBase64(url);
      /* #endif */

      /* #ifdef MP-WEIXIN */
      baseStr = await wx_imageToBase64(url);
      /* #endif */

      /* #ifdef APP-PLUS */
      baseStr = await App_imgToBase(url);
      /* #endif */
      callback(baseStr);
    },
  },
};
</script>

<style lang="scss" scoped>
</style>